package com.lsk.netdisk.auth.mail;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Component
public class MyMailSender {
	 @Autowired
	 private JavaMailSenderImpl sender;

	 public void sendRegisterCode(String to, String regCode){
		 SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
		 simpleMailMessage.setSubject("Register");
		 simpleMailMessage.setTo(to);
		 simpleMailMessage.setFrom("3075929352@qq.com");
		 simpleMailMessage.setText("Your register code is: "+regCode);
		 sender.send(simpleMailMessage);
	 }
	 public void sendRePasswordURL(String to, String url) throws MessagingException {
	 	String content = "<html><body>点击<a href=\""+url+"\">链接</a>更改密码</body></html>";
	 	MimeMessage mimeMessage = sender.createMimeMessage();
	 	MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage,true);
	 	mimeMessageHelper.setFrom("3075929352@qq.com");
	 	mimeMessageHelper.setTo(to);
	 	mimeMessageHelper.setSubject("重置密码");
	 	mimeMessageHelper.setText(content,true);
	 	sender.send(mimeMessage);
	 }
}
